<template>
    <div class="login-page" @mousemove="handleMouseMove">
      <div class="cursor-follower"></div>
      <div class="cursor-follower-small"></div>
      <div class="orange"> </div>
      <div class="blue"></div>
      <div class="blue small"></div>
      <div class="login-box">
        <div class="logo-box">
          <img src="@/assets/logo.png">
          <div>
            <div class="sys-name">Lab-OJ</div>
            <div class="sys-sub-name">人工智能与计算机学院双创实验室在线考核平台</div>
          </div>
        </div>
        <div class="form-box-title">
          <span>验证码登录</span>
        </div>
        <div class="form-box">
          <div class="form-item">
            <img src="@/assets/images/email.png">
            <el-input v-model="mobileForm.email" type="text" placeholder="请输入邮箱地址" />
          </div>
          <div class="form-item">
            <img src="@/assets/images/code.png">
            <el-input style="width:134px" v-model="mobileForm.code" type="text" placeholder="请输入验证码" />
            <div class="code-btn-box" @click="getCode">
              <span>{{ txt }}</span>
            </div>
          </div>
          <div class="submit-box" @click="loginFun">
            登录/注册
          </div>
        </div>
        <div class="gray-bot">
          <p>注册或点击登录代表您同意 <span>服务条款</span> 和 <span>隐私协议</span></p>
        </div>
      </div>
    </div>
  </template>
  <script setup>
   import { sendCodeService, codeLoginService } from '@/apis/user'
   import router from '@/router'
   import { ref, reactive, onMounted, onUnmounted } from 'vue'
   import { setToken } from '@/utils/cookie.js'
  
  // 验证码登录表单
  let mobileForm = reactive({
    email: '',
    code: ''
  })

   let txt = ref('获取验证码')
  let timer = null
  async function getCode() {
    await sendCodeService(mobileForm)
    txt.value = '59s'
    let num = 59
    timer = setInterval(() => {
      num--
      if (num < 1) {
        txt.value = '重新获取验证码'
        clearInterval(timer)
      } else {
        txt.value = num + 's'
      }
    }, 1000)
  }
  
  async function loginFun() {
    const loginRef = await codeLoginService(mobileForm)
    setToken(loginRef.data)
    router.push('/c-oj/home/question')
  }

  const mouseX = ref(0)
  const mouseY = ref(0)
  const windowWidth = ref(0)
  const windowHeight = ref(0)

  function handleMouseMove(e) {
    mouseX.value = e.clientX
    mouseY.value = e.clientY
  }

  onMounted(() => {
    document.body.style.cursor = 'none'
    windowWidth.value = window.innerWidth
    windowHeight.value = window.innerHeight
    
    window.addEventListener('resize', () => {
      windowWidth.value = window.innerWidth
      windowHeight.value = window.innerHeight
    })
  })

  onUnmounted(() => {
    document.body.style.cursor = 'auto'
    window.removeEventListener('resize', () => {
      windowWidth.value = window.innerWidth
      windowHeight.value = window.innerHeight
    })
  })
  </script>
  <style lang="scss" scoped>
  .login-page {
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
  
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: 
        radial-gradient(circle at v-bind('mouseX + "px"') v-bind('mouseY + "px"'), rgba(50, 197, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at v-bind('(windowWidth - mouseX) + "px"') v-bind('(windowHeight - mouseY) + "px"'), rgba(240, 113, 74, 0.1) 0%, transparent 50%);
      animation: gradientMove 15s ease infinite;
      transition: background-position 0.1s ease-out;
    }
  
    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: 
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2332c5ff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
      opacity: 0.5;
      animation: backgroundMove 20s linear infinite;
    }
  
    .login-box {
      width: 480px;
      background: #FFFFFF;
      border-radius: 24px;
      position: relative;
      z-index: 2;
      padding: 48px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
      animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  
      .logo-box {
        display: flex;
        align-items: center;
        margin-bottom: 40px;
  
        img {
          width: 64px;
          height: 64px;
          margin-right: 16px;
          border-radius: 16px;
          background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
          box-shadow: 0 4px 12px rgba(50, 197, 255, 0.3);
          transition: all 0.3s ease;
  
          &:hover {
            transform: scale(1.05);
          }
        }
  
        .sys-name {
          font-family: PingFangSC, PingFang SC;
          font-weight: 600;
          font-size: 28px;
          color: #1e293b;
          line-height: 1.4;
          margin-bottom: 8px;
          background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
        }
  
        .sys-sub-name {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #64748b;
          line-height: 1.5;
        }
      }
  
      .form-box-title {
        margin-bottom: 32px;
  
        span {
          font-family: PingFangSC, PingFang SC;
          font-weight: 600;
          font-size: 24px;
          color: #1e293b;
          line-height: 1.4;
          position: relative;
          padding-left: 16px;
  
          &::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 20px;
            background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
            border-radius: 2px;
          }
        }
      }
  
      .gray-bot {
        margin-top: 32px;
        text-align: center;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #64748b;
        line-height: 1.5;
  
        p {
          margin: 0;
        }
  
        span {
          color: #32C5FF;
          cursor: pointer;
          transition: all 0.3s ease;
          position: relative;
  
          &::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 100%;
            height: 1px;
            background: #32C5FF;
            transform: scaleX(0);
            transform-origin: right;
            transition: transform 0.3s ease;
          }
  
          &:hover::after {
            transform: scaleX(1);
            transform-origin: left;
          }
        }
      }
  
      :deep(.form-box) {
        .submit-box {
          margin-top: 40px;
          width: 100%;
          height: 48px;
          background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
          border-radius: 12px;
          cursor: pointer;
          display: flex;
          justify-content: center;
          align-items: center;
          font-family: PingFangSC, PingFang SC;
          font-weight: 600;
          font-size: 16px;
          color: #FFFFFF;
          letter-spacing: 1px;
          transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
          box-shadow: 0 4px 12px rgba(50, 197, 255, 0.3);
  
          &:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 16px rgba(50, 197, 255, 0.4);
          }
  
          &:active {
            transform: translateY(2px);
          }
        }
  
        .form-item {
          display: flex;
          align-items: center;
          width: 100%;
          height: 48px;
          background: #f8fafc;
          border-radius: 12px;
          margin-bottom: 24px;
          position: relative;
          transition: all 0.3s ease;
          border: 1px solid transparent;
  
          &:hover {
            background: #fff;
            border-color: rgba(50, 197, 255, 0.2);
          }
  
          &:focus-within {
            background: #fff;
            border-color: #32C5FF;
            box-shadow: 0 0 0 2px rgba(50, 197, 255, 0.2);
          }
  
          .code-btn-box {
            position: absolute;
            right: 0;
            width: 120px;
            height: 48px;
            background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
            border-radius: 12px;
            top: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.3s ease;
  
            &:hover {
              transform: translateY(-1px);
              box-shadow: 0 4px 12px rgba(50, 197, 255, 0.3);
            }
  
            &:active {
              transform: translateY(1px);
            }
  
            span {
              font-family: PingFangSC, PingFang SC;
              font-weight: 500;
              font-size: 14px;
              color: #FFFFFF;
            }
          }
  
          .el-input {
            width: 100%;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 14px;
            color: #1e293b;
          }
  
          .el-input__wrapper {
            border: none;
            box-shadow: none;
            background: transparent;
            padding-left: 0;
          }
  
          img {
            width: 20px;
            height: 20px;
            margin: 0 16px;
            opacity: 0.6;
            transition: all 0.3s ease;
          }
  
          &:hover img {
            opacity: 1;
          }
        }
      }
    }
  
    .orange {
      background: #F0714A;
      width: 600px;
      height: 600px;
      border-radius: 50%;
      opacity: 0.1;
      filter: blur(80px);
      position: absolute;
      left: v-bind('mouseX/20 + "%"');
      top: v-bind('mouseY/20 + "%"');
      animation: float 6s ease-in-out infinite, pulse 4s ease-in-out infinite;
      transition: all 0.3s ease-out;
    }
  
    .blue {
      width: 500px;
      height: 500px;
      background: #32C5FF;
      opacity: 0.1;
      filter: blur(80px);
      position: absolute;
      right: v-bind('(windowWidth - mouseX)/20 + "%"');
      top: v-bind('mouseY/20 + "%"');
      border-radius: 50%;
      animation: float 8s ease-in-out infinite, pulse 6s ease-in-out infinite;
      transition: all 0.3s ease-out;
  
      &.small {
        width: 300px;
        height: 300px;
        top: v-bind('(windowHeight - mouseY)/10 + "%"');
        right: v-bind('(windowWidth - mouseX)/10 + "%"');
        animation: float 10s ease-in-out infinite, pulse 8s ease-in-out infinite;
      }
    }
  
    .particles {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      z-index: 1;
  
      .particle {
        position: absolute;
        width: 4px;
        height: 4px;
        background: rgba(50, 197, 255, 0.3);
        border-radius: 50%;
        animation: particleFloat 15s linear infinite;
        transform-origin: v-bind('mouseX + "px"') v-bind('mouseY + "px"');
  
      
      }
    }
  }
  
  @keyframes slideUp {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  @keyframes gradientMove {
    0% {
      background-position: 0% 0%;
    }
    50% {
      background-position: 100% 100%;
    }
    100% {
      background-position: 0% 0%;
    }
  }
  
  @keyframes backgroundMove {
    0% {
      background-position: 0 0;
    }
    100% {
      background-position: 60px 60px;
    }
  }
  
  @keyframes float {
    0%, 100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-20px);
    }
  }
  
  @keyframes pulse {
    0%, 100% {
      opacity: 0.1;
    }
    50% {
      opacity: 0.2;
    }
  }
  
  @keyframes particleFloat {
    0% {
      transform: translateY(0) translateX(0);
      opacity: 0;
    }
    10% {
      opacity: 1;
    }
    90% {
      opacity: 1;
    }
    100% {
      transform: translateY(-100vh) translateX(100px);
      opacity: 0;
    }
  }

  .cursor-follower {
    position: fixed;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(50, 197, 255, 0.1) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    transition: transform 0.1s ease-out;
    transform: translate(-50%, -50%);
    left: v-bind('mouseX + "px"');
    top: v-bind('mouseY + "px"');
    z-index: 1;
  }

  .cursor-follower-small {
    position: fixed;
    width: 20px;
    height: 20px;
    background: rgba(50, 197, 255, 0.2);
    border-radius: 50%;
    pointer-events: none;
    transition: transform 0.1s ease-out;
    transform: translate(-50%, -50%);
    left: v-bind('mouseX + "px"');
    top: v-bind('mouseY + "px"');
    z-index: 2;
  }
  </style>